# About Dialog module for CROSS

#########################################################################################
#
# Copyright (C) 2008  
# Authors: Aljosa Osep (aljosa.osep@gmail.com), Jernej Kranjec (jernej.kranjec@gmail.com)
# From Faculty of Electrical Engineering and Computer Science, Maribor, Slovenia
# Done at School of Technology, Seinajoki, Finland
# Under mentor Kimmo Salmenjoki (kimmo.salmenjoki@seamk.fi)
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
#
#########################################################################################

# ==================== imports ====================== #
import sys
sys.path.append('Modules/GUI/Widgets')

import pygtk            # import pygtk library
pygtk.require('2.0')    # require version 2.o
import gtk 	        # import gtk

import tabWidgetsModule # custom widgets used here	

############################
# about dialog class
############################
class aboutDialog(gtk.Dialog):
	#initialisation
	def __init__(self):
		gtk.Dialog.__init__(self, "About CROSS", buttons=("License", 1, gtk.STOCK_OK, gtk.RESPONSE_OK))
		self.set_resizable(False)				# fixed window
		self.set_size_request(370, 300)				# size 300x450px

		label = gtk.Label()					# main label
		label.set_use_markup(True)				# enable pango styles
		label.set_markup("<b>CROSS</b>\nCHUMP RFID Standalone On Serial\n\n<u>Authors:</u>\nAljosa Osep <i>aljosa.osep@gmail.com</i>\nJernej Kranjec <i>jernej.kranjec@gmail.com</i>\nOctober 2008\n\n<i>University of Applied Sciences, Seinajoki\nSchool of Technology, Finland\n\nUniversity of Electrical Engeneering and\nComputer Science, Maribor(FERI), Slovenia</i>")
		self.vbox.pack_start(label, True, True, 0)		# pack label
		label.show()						# and show label

		response = self.run()					# get response from dialog

		if response == 1:					# show license window	
			licenseWindow = licenseDialog()			# create instance
			licenseWindow.show()				# show dialog
		#	return licenseWindow.ret		

		self.destroy()
		self.ret = None

############################
# license dialog class
############################
class licenseDialog(gtk.Dialog):
	#initialisation
	def __init__(self):
		gtk.Dialog.__init__(self, "CROSS license", buttons=(gtk.STOCK_OK, gtk.RESPONSE_OK))
		self.set_resizable(False)						# fixed window
		self.set_size_request(370, 300)						# size 300x450px

		self.sw = gtk.ScrolledWindow()						# create scrolled window
		self.sw.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)		# set automatic policy
		self.text_box = gtk.TextView()						# create text view
		self.textbuffer = self.text_box.get_buffer()				# textbuffer for texview
		self.sw.add(self.text_box)						# add textview to scroller
		self.sw.show()								# show scrolled window
		self.text_box.show()

		# license text
		self.textbuffer.set_text("This program is free software: you can redistribute it and/or modify\nit under the terms of the GNU General Public License as published by\nthe Free Software Foundation, either version 3 of the License, or\nany later version.\n\nThis program is distributed in the hope that it will be useful,\nbut WITHOUT ANY WARRANTY; without even the implied warranty of\nMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\nGNU General Public License for more details.\n\nYou should have received a copy of the GNU General Public License\nalong with this program.  If not, see <http://www.gnu.org/licenses/>.")

		self.vbox.pack_start(self.sw, True, True, 0)				# pack text control
		self.vbox.show()							# show vbox

		response = self.run()							# get response from dialog
	
		if response == gtk.RESPONSE_OK:						# destroy window	
			self.destroy()			


	#	self.destroy()
		#self.ret = None


############################
# help dialog class
############################
class helpDialog(gtk.Dialog):
	# methods
	def message_box(self, message):
		self.msg_dialog = gtk.MessageDialog(None, gtk.DIALOG_MODAL,gtk.MESSAGE_INFO, gtk.BUTTONS_OK, message)

		self.msg_dialog.run()
		self.msg_dialog.destroy()

	#initialisation
	def __init__(self):
		gtk.Dialog.__init__(self, "Help", buttons=(gtk.STOCK_OK, gtk.RESPONSE_OK))
		#self.set_resizable(False)						# fixed window
		self.set_size_request(600, 500)						# size 300x450px

		self.sw = gtk.ScrolledWindow()						# create scrolled window
		self.sw.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)		# set automatic policy
		self.text_box = gtk.TextView()						# create text view
		self.textbuffer = self.text_box.get_buffer()				# textbuffer for texview
		self.sw.add(self.text_box)						# add textview to scroller
		self.text_box.set_editable(False)	
		self.sw.show()								# show scrolled window
		self.text_box.show()


		self.vbox.pack_start(self.sw, True, True, 0)				# pack text control
		self.vbox.show()							# show vbox

		self.help_string = ""
		global f		
		try:
			f = open("help.txt", 'r')
			for line in f:
				self.help_string = self.help_string + line

		except ValueError:
			self.message_box("Error! It seems that help file is corrupted.")
#			print "Error! It seems that config file is corrupted."
			self.help_string = "Help file missing or corrupt."


		except IOError:
			self.message_box("Error! Problem with opening help file.")
#			print "Error! Problem with opening file."
			self.help_string = "Help file missing or corrupt."

		finally:
			f.close()

		self.textbuffer.set_text(self.help_string)

		response = self.run()							# get response from dialog
	
		if response == gtk.RESPONSE_OK:						# destroy window	
			self.destroy()			


	#	self.destroy()
		self.ret = None
		
